package com.itheima.web;

import com.itheima.pojo.Brand;
import com.itheima.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectAllServlet")
public class SelectAllServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.调用Service层的查询所有功能
        BrandService brandService = new BrandService();
        List<Brand> brands = brandService.selectAll();

        // 2.把查询的数据放到request中
        request.setAttribute("brands", brands);

        // 3.转到jsp去显示数据
        request.getRequestDispatcher("/brandList.jsp").forward(request, response);
    }
}
